package com.lost.octopus.es.processor.util;

import com.sunsharing.share.boot.framework.code.CodeLoader;
import com.lost.octopus.es.processor.constant.Constant;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.context.ApplicationContext;

import java.util.Arrays;
import java.util.HashSet;

/**
 * spring全局静态实例操作工具
 * @author zhangbh
 **/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ApplicationUtil {
    private static ApplicationContext applicationContext;

    public static void setApplicationContext(ApplicationContext applicationContext) {
        ApplicationUtil.applicationContext = applicationContext;
    }

    public static String transDm(String alias, String value) {
        CodeLoader bean = ApplicationUtil.applicationContext.getBean(CodeLoader.class);
        return bean.getCodeStrToZw(value, alias);
    }

    public static <T> T getBean(Class<T> clazz) {
        return applicationContext.getBean(clazz);
    }

    public static Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
    }


    public static HashSet<String> getHashSet(String str) {
        if (StringUtils.isBlank(str)) {
            return new HashSet<>();
        }
        return new HashSet<>(Arrays.asList(str.split(Constant.SEPARATOR)));
    }
}
